﻿/// <reference path="jquery-1.4.2.min.js" />

LoadJS("/!js/uploadify-v2.1.4/swfobject.js");
LoadJS("/!js/uploadify-v2.1.4/jquery.uploadify.v2.1.4.min.js");
LoadJS("/!js/validate.js");
LoadCSS("/!js/uploadify-v2.1.4/uploadify.css");

var queuesize = 1;
$(document).ready(function () {
    var servicedate = $("[id$=hfadddate]").val().split('-');
    //图片上传
    $("#uploadify").uploadify(
        {
            'uploader': '/!js/uploadify-v2.1.4/uploadify.swf',
            'script': '/Handler/UploadHandler.ashx',
            'cancelImg': '/!js/uploadify-v2.1.4/cancel.png',
            'folder': "/UploadFile/Temp/Image/" + servicedate[0] + "/" + servicedate[1] + "/" + servicedate[2] + "/",
            'queueID': 'fileQueue',
            'auto': true,
            'multi': true,
            'fileExt': '*.jpg;*.png',
            'fileDesc': '请选择jpg , png文件...',
            'buttonImg': '/!js/uploadify-v2.1.4/btn_uploadimg.jpg',
            'wmode': 'transparent',
            'queueSizeLimit': queuesize,
            'scriptData': { 'ASPSESSID': $('#hfAspSessID').val(), 'AUTHID': $('#hfAuth').val() },
            'onComplete': function (event, queueID, fileObj, response, data) {
                if (response.indexOf('UploadFile') != -1) {
                    showImage(response);
                }
                else {
                    alert(response);
                }
            },
            'onError': function (a, b, c, d) {
                if (d.status == 404) alert('Could not find upload script. Use a path relative to: ' + '<?= getcwd() ?>');
                else if (d.type === "HTTP") alert('error ' + d.type + ": " + d.info);
                else if (d.type === "File Size") alert(c.name + ' ' + d.type + ' Limit: ' + Math.round(d.sizeLimit / 1024) + 'KB');
                else
                    alert('error ' + d.type + ": " + d.info);
            }
        }
    );


    //显示上传后的图片，显示数目为queuesize
    function showImage(response) {
        if ($('#showQueue img').length < queuesize) {
        }
        else {
            $('#showQueue img:eq(0)').remove();
        }
        $('<img>').addClass('photo').appendTo($('#showQueue')) .width('75px').height('75px').attr('src', response).attr('alt', ' ').attr('title', '双击删除该图片').dblclick(function () {
            $(this).remove();
            setPathList();
        }); ;
        setPathList();
        $('#hfpath').next('span').removeClass('error');
    }

    function setPathList() {
        var imglist = $('#showQueue img');
        var pathlist = "";
        for (var i = 0; i < imglist.length; i++) {
            if (i == 0) {
                pathlist = $(imglist[i]).attr('src');
            }
            else {
                pathlist += ',' + $(imglist[i]).attr('src');
            }
        }
        $('#hfpath').val(pathlist);
    }



    //视频上传
    $("#videouploadify").uploadify(
            {
                'uploader': '/!js/uploadify-v2.1.4/uploadify.swf',
                'script': '/Handler/UploadHandler.ashx',
                'cancelImg': '/!js/uploadify-v2.1.4/cancel.png',
                'folder': "/UploadFile/Temp/Video/" + servicedate[0] + "/" + servicedate[1] + "/" + servicedate[2] + "/",
                'queueID': 'videoQueue',
                'auto': true,
                'multi': true,
                'fileExt': '*.avi;*.mov;*.mpg;*.mp4;*.flv;*.wmv',
                'fileDesc': '请选择avi,mov,mpg,mp4,flv文件...',
                'buttonImg': '/!js/uploadify-v2.1.4/btn_uploadvideo.jpg',
                'wmode': 'transparent',
                'queueSizeLimit': 1,
                'scriptData': { 'ASPSESSID': $('#hfAspSessID').val(), 'AUTHID': $('#hfAuth').val() },
                'onComplete': function (event, queueID, fileObj, response, data) {
                    $("#hfvideopath").val(response);
                },
                'onError': function (a, b, c, d) {
                    if (d.status == 404) alert('Could not find upload script. Use a path relative to: ' + '<?= getcwd() ?>');
                    else if (d.type === "HTTP") alert('error ' + d.type + ": " + d.info);
                    else if (d.type === "File Size") alert(c.name + ' ' + d.type + ' Limit: ' + Math.round(d.sizeLimit / 1024) + 'KB');
                    else
                        alert('error ' + d.type + ": " + d.info);
                }
            }
        );
});


